import './assets/main.css'

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import { createRouter, createWebHistory } from 'vue-router'

import App from './App.vue'

// Import routes
import { routes } from './router/index'

/**
 * 初始化应用程序
 * 简化版本，用于调试启动问题
 */
async function initializeApp() {
  try {
    console.log('开始初始化Vue应用...')
    
    // Create router
    const router = createRouter({
      history: createWebHistory(),
      routes
    })
    
    // Create app
    const app = createApp(App)
    
    // Use plugins
    app.use(createPinia())
    app.use(router)
    
    // Mount app
    app.mount('#app')
    
    console.log('Vue跑酷游戏应用初始化完成')
    
  } catch (error) {
    console.error('应用初始化失败:', error)
    console.error('错误堆栈:', error.stack)
    
    // 显示错误信息给用户
    const errorDiv = document.createElement('div')
    errorDiv.innerHTML = `
      <div style="
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        background: white;
        padding: 2rem;
        border-radius: 8px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.3);
        text-align: center;
        max-width: 500px;
        z-index: 10000;
        font-family: Arial, sans-serif;
      ">
        <h2 style="color: #dc2626; margin-bottom: 1rem;">应用启动失败</h2>
        <p style="margin-bottom: 1rem; color: #6b7280;">
          错误信息: ${error.message}
        </p>
        <p style="margin-bottom: 1.5rem; color: #6b7280; font-size: 0.9rem;">
          请打开浏览器开发者工具查看详细错误信息
        </p>
        <button onclick="window.location.reload()" style="
          background: #3b82f6;
          color: white;
          border: none;
          padding: 0.75rem 1.5rem;
          border-radius: 6px;
          cursor: pointer;
          font-size: 1rem;
        ">
          刷新页面
        </button>
      </div>
      <div style="
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 9999;
      "></div>
    `
    document.body.appendChild(errorDiv)
  }
}

// 启动应用
initializeApp()